/* $Id: CategoryListAdapter.java 58 2007-12-09 21:15:59Z benjamin.stover $
 * 
 * Undroid Package Manager
 *
 * Copyright 2007 Steven Osborn
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.bitsetters.undroid;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


/**
 * 
 * @author Steven Osborn - http://steven.bitsetters.com
 */
public class CategoryListAdapter extends BaseAdapter {

	/**
	 * Remember our context so we can use it when constructing views.
	 */
	private Context mContext;

	private List<Category> mItems;

	/**
	 * 
	 * @param context
	 */
	public CategoryListAdapter(Context context) {
		mContext = context;
		mItems  = new ArrayList<Category>();
	}

	/**
	 * 
	 * @param bt
	 */
	public void addItem(Category bt) {
		mItems.add(bt);
	}

	/**
	 * 
	 * @param bti
	 */
	public void setListItems(List<Category> bti) {
		mItems = bti;
	}

	/**
	 * The number of items in the
	 */
	public int getCount() {
		return mItems.size();
	}

	/**
	 * 
	 */
	public Object getItem(int position) {
		return mItems.get(position);
	}

	/**
	 * 
	 */
	public boolean areAllItemsSelectable() {
		return false;
	}

	/**
	 * 
	 */
	public boolean isSelectable(int position) {
		return mItems.get(position).isSelectable();
	}

	/**
	 * Use the array index as a unique id.
	 */
	public long getItemId(int position) {
		return position;
	}

	/**
	 * Make a CategoryView to hold each row.
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		CategoryListView btv;
		if (convertView == null) {
			btv = new CategoryListView(mContext, mItems.get(position).getText(),
					mItems.get(position).getBullet(),mItems.get(position).getCount());
		} else {
			btv = (CategoryListView) convertView;
			btv.setText(mItems.get(position).getText());
			btv.setIcon(mItems.get(position).getBullet());
		}

		return btv;
	}
}
